package gui.crud;

import gui.util.NumberOnlyListener;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import domain.Accountable;
import domain.Professor;

public class ProfessorRegisterPane extends AbstractRegisterPanel {

	private JTextField registrationField;
	private JLabel registrationLabel;
	
	public ProfessorRegisterPane() {
		super("Cadastro de Professor", 400, 300);
	}

	@Override
	protected void registerAct() {
		String name = getNameField().getText();
		String registration = registrationField.getText();
		try {
			Accountable p = new Professor(name, registration);
			//TeacherHandler.add(p);
			JOptionPane.showMessageDialog(this, "Professor cadastrado com sucesso!", "Cadastro", JOptionPane.INFORMATION_MESSAGE);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
		} finally {
			getNameField().setText("");
			registrationField.setText("");
		}
	}

	@Override
	protected void setUpNewComponents() {
		registrationField = new JTextField();
		registrationField.setBounds(200, 60, 90, 20);
		registrationField.addKeyListener(new NumberOnlyListener());
		registrationLabel = new JLabel("<html><i><b>Matricula:</b></i></html>");
		registrationLabel.setBounds(200, 38, 120, 20);
	
	}

	@Override
	protected void addNewComponents() {
		this.add(registrationField);
		this.add(registrationLabel);
	}

}
